package com.example.boot3new.config;

import com.example.boot3new.demos.web.MyUserHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.servlet.function.RequestPredicate;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.ServerResponse;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import static org.springframework.web.servlet.function.RequestPredicates.accept;
import static org.springframework.web.servlet.function.RouterFunctions.route;

/**
 *SpringBoot3新特性
 *  Problemdetails错误信息返回新格式
 *      自动配置包含，配置spring.webflux.problemdetails.enabled=true开该功能
 *  函数式web  路由和业务分离
 * @author lhq
 * @date 2023/05/30 17:02
 */
@Configuration(proxyBeanMethods = false)
public class MyRoutingConfiguration {

    private static final RequestPredicate ACCEPT_JSON = accept(MediaType.APPLICATION_JSON);
    @Bean
    public RouterFunction<ServerResponse> routerFunction(MyUserHandler userHandler){

        return  route()
                .GET("/user",ACCEPT_JSON,userHandler::getUser)
                .build();
    }




}
